package kr.pe.johnkim.carrotpoint.mobile.controller;

import kr.pe.johnkim.carrotpoint.mobile.domain.CarrotPointMerchantMarketing;
import kr.pe.johnkim.carrotpoint.mobile.service.CarrotPointMerchantMarketingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Carrot Point 가맹점 마케팅 관련 controller 클래스 이다.
 *
 * @author : John_Kim <cale9797@gmail.com>
 * @date : 13. 2. 6.
 */
@Controller
@RequestMapping(value = "/carrotPointMerchantMarketingController")
public class CarrotPointMerchantMarketingController {

    // SLF4J Logging
    private Logger logger = LoggerFactory.getLogger(CarrotPointMerchantMarketingController.class);

    @Autowired
    private CarrotPointMerchantMarketingService carrotPointMerchantMarketingService;

    /**
     * 가맹점 마케팅을 등록 한다.
     *
     * @param carrotPointMerchantMarketing
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/registerMerchantMarketing", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public CarrotPointMerchantMarketing registerMerchantMarketing
            (@RequestBody CarrotPointMerchantMarketing carrotPointMerchantMarketing) throws Exception {
        logger.info("registerMerchantMarketing");

        CarrotPointMerchantMarketing result = new CarrotPointMerchantMarketing();

        try {
            carrotPointMerchantMarketingService.registerMerchantMarketing(carrotPointMerchantMarketing);
            result.setResult("SUCCESS");
            logger.info("success to register merchant marketing.");
        } catch (Exception e) {
            result.setResult("FAIL");
            logger.info("fail to register merchant marketing.");
        }

        return result;
    }

    /**
     * 가맹점 마케팅 목록을 가져 온다.
     *
     * @param carrotPointMerchantMarketing
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getMerchantMarketingList", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public List<CarrotPointMerchantMarketing> getMerchantMarketingList
            (@RequestBody CarrotPointMerchantMarketing carrotPointMerchantMarketing) throws Exception {
        logger.info("getMerchantMarketingList");

        logger.info("carrotPointMerchantMerchantId : {}", carrotPointMerchantMarketing.getCarrotPointMerchantMerchantId());
        logger.info("activateYn                    : {}", carrotPointMerchantMarketing.getActivateYn());

        return this.carrotPointMerchantMarketingService.getMerchantMarketingList(carrotPointMerchantMarketing);
    }

    /**
     * 가맹점 마케팅 내용을 가져 온다.
     *
     * @param carrotPointMerchantMarketing
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getMerchantMarketingInformation", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public CarrotPointMerchantMarketing getMerchantMarketingInformation
            (@RequestBody CarrotPointMerchantMarketing carrotPointMerchantMarketing) throws Exception {
        logger.info("getMerchantMarketingInformation");

        logger.info("idCarrotPointMerchantMarketing : {}", carrotPointMerchantMarketing.getIdCarrotPointMerchantMarketing());
        logger.info("activateYn                     : {}", carrotPointMerchantMarketing.getActivateYn());

        return this.carrotPointMerchantMarketingService.getMerchantMarketingInformation(carrotPointMerchantMarketing);
    }

    /**
     * 가맹점 마케팅 내용을 업데이트 한다.
     *
     * @param carrotPointMerchantMarketing
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/updateMerchantMarketingInformation", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public CarrotPointMerchantMarketing updateMerchantMarketingInformation
            (@RequestBody CarrotPointMerchantMarketing carrotPointMerchantMarketing) throws Exception {
        logger.info("updateMerchantMarketingInformation");

        CarrotPointMerchantMarketing result = new CarrotPointMerchantMarketing();

        try {
            carrotPointMerchantMarketingService.updateMerchantMarketingInformation(carrotPointMerchantMarketing);
            result.setResult("SUCCESS");
            logger.info("success to update marketing information.");
        } catch (Exception e) {
            result.setResult("FAIL");
            logger.error("fail to update marketing information.");
        }

        return result;
    }

    /**
     * 가맹점 마케팅을 비활성화 한다.
     *
     * @param carrotPointMerchantMarketing
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/updateDeactivateMerchantMarketing", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public CarrotPointMerchantMarketing updateDeactivateMerchantMarketing
            (@RequestBody CarrotPointMerchantMarketing carrotPointMerchantMarketing) throws Exception {
        logger.error("updateDeactivateMerchantMarketing");

        logger.info("idCarrotPointMerchantMarketing : {}", carrotPointMerchantMarketing.getIdCarrotPointMerchantMarketing());
        logger.info("carrotPointMerchantMerchantId  : {}", carrotPointMerchantMarketing.getCarrotPointMerchantMerchantId());
        logger.info("activateYn                     : {}", carrotPointMerchantMarketing.getActivateYn());
        logger.info("modifyDate                     : {}", carrotPointMerchantMarketing.getModifyDate());

        CarrotPointMerchantMarketing result = new CarrotPointMerchantMarketing();

        try {
            carrotPointMerchantMarketingService.updateDeactivateMerchantMarketing(carrotPointMerchantMarketing);
            result.setResult("SUCCESS");
            logger.info("success to update deactivate merchant marketing.");
        } catch (Exception e) {
            result.setResult("FAIL");
            logger.error("fail to update deactivate merchant marketing.");
        }

        return result;
    }
}
